// ================================================================================
// 		File: PartyGrassrootsGroupItemMember.cs
// 		Desc: 
//  
// 		Called by:   
//               
// 		Auth: chenwenzhi（）
// 		Date: 2016-06-11 23:56
// ================================================================================
// 		Change History
// ================================================================================
// 		Date:		Author:				Description:
// 		--------	--------			-------------------
//    
// ================================================================================
// 
// ================================================================================
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq; 
using System.Text;
using MySql.Data.MySqlClient;
using ZHDJ.Core;

namespace ZHDJ.Data.Models.Grassroots
{
    /// <summary>
    /// 小组成员
    /// </summary>   
    public class PartyGrassrootsGroupItemMember : EntityBase
    { 
		#region 属性
       
		
        /// <summary>
        /// 所属小组
        /// </summary>
        public string ItemID { get; set; }
		
        /// <summary>
        /// 用户ID
        /// </summary>
        public string LoginID { get; set; }
		
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }
		
        /// <summary>
        /// 单位职务
        /// </summary>
        public string Post { get; set; }
		
        /// <summary>
        /// 电话
        /// </summary>
        public string MobileNo { get; set; }
		
        /// <summary>
        /// 职责分类（系统参数）
        /// </summary>
        public string DutyCategory { get; set; }
		
        /// <summary>
        /// 图片ID
        /// </summary>
        public string ImageID { get; set; }

		/// <summary>
        /// 排序
        /// </summary>
        public int OrderNo { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        public string CreateBy { get; set; }
		
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }
		
        /// <summary>
        /// 修改人
        /// </summary>
        public string ModifyBy { get; set; }
		
        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime? ModifyTime { get; set; }
		
		#endregion 

		#region 查询管理

		 public static DataSet GetGridData(int pageIndex, int pageSize,string itemId="", string dutyCategory="", string searchKey = "")
        {
            List<MySqlParameter> parameters = new List<MySqlParameter>()
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "DutyCategoryType",Value = SysDataDictionary.GrassrootsDutyCategory}
                
            };


            StringBuilder sb = new StringBuilder();
            sb.Append(@"select SQL_CALC_FOUND_ROWS  data.ID,data.ItemID,data.LoginID,data.UserName,data.Post,data.MobileNo,data.OrderNo,
data.DutyCategory,data.ImageID,data.CreateBy,data.CreateTime,data.ModifyBy,data.ModifyTime,
d.DDicMemberName as DutyCategoryName
                        from tblPartyGrassrootsGroupItemMember data

left join tbldatadictionary d on (d.DDicType=?DutyCategoryType and data.DutyCategory=d.DDicMember)
                        where 1=1 ");
            if (!string.IsNullOrEmpty(itemId))
            {
                sb.Append(" and data.itemId = ?itemId ");
                parameters.Add(
                    new MySqlParameter() { DbType = DbType.String, ParameterName = "itemId", Value = itemId });
            }
            if (!string.IsNullOrEmpty(dutyCategory))
            {
                sb.Append(" and data.dutyCategory = ?dutyCategory ");
                parameters.Add(
                   new MySqlParameter() { DbType = DbType.String, ParameterName = "DutyCategory", Value = dutyCategory });
            }
            if (!string.IsNullOrEmpty(searchKey))
            {
                sb.Append(" and data.UserName like ?key ");
                parameters.Add(
                    new MySqlParameter() { DbType = DbType.String, ParameterName = "key", Value = string.Format("%{0}%", searchKey) });
            }

            sb.Append(" order by data.CreateTime desc LIMIT ?Begin ,?PageSize;SELECT FOUND_ROWS();");
            return MySqlHelper.ExecuteDataSet(sb.ToString(), parameters.ToArray());
        }
		#endregion
    }
}
